﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Lib
{
    public class CreateCode
    {
        public static string CreateCode10(string first,string last)
        {
            int l = 10 - (first.Length - last.Length);
            for (int i = 1; i <= l; i++)
            {
                first += "0";
            }
            first += last;
            return first;
        }
        public static string CreateCode3(string first, string last)
        {
            int l = 3 - (first.Length + last.Length);
            for (int i = 1; i <= l; i++)
            {
                first += "0";
            }
            first += last;
            return first;
        }
        public static string CreateCode6(string first, string last)
        {
            int l = 6 - (first.Length - last.Length);
            for (int i = first.Length; i <= l; i++)
            {
                first += "0";
            }
            first += last;
            return first;
        }
        public static string CreateCode8(string first, string last)
        {
            int l = 8 - (first.Length - last.Length);
            for (int i = first.Length; i <= l; i++)
            {
                first += "0";
            }
            first += last;
            return first;
        }
        public static string CreateCode10Random()
        {
            Random random = new Random();
            string code = "";
            for (int i = 0; i < 10; i++)
            {
                code += random.Next(0, 9).ToString();
            }
            return code;

        }
        public static string Encode(string original, string key)
        {
            string str = "";
            char[] arr = original.ToCharArray();
            foreach (char c in arr)
            {
                str += (Convert.ToInt32(c) * int.Parse(key));
                str += key;
                str += "-";
            }
            str = str.Substring(0, str.Length - 1);
            return str;
        }
        public static string Decode(string original)
        {
            string str = "";
            string[] arr = original.Split('-');
            foreach (string c in arr)
            {
                int key = int.Parse(c.Substring(c.Length - 1));
                char s = Convert.ToChar((Convert.ToInt32(c.Substring(0, c.Length - 1)) / key));
                str += s;
            }
            return str;
        }
    }
}
